package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ExtHelper;
import com.ruoyi.common.utils.uuid.IdGeneratorSnowflake;
import com.ruoyi.system.domain.MentorClassify;
import com.ruoyi.system.mapper.MentorClassifyMapper;
import com.ruoyi.system.service.IMentorClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 导师分类Service业务层处理
 *
 * @author dp
 * @date 2023-11-27
 */
@Service
public class MentorClassifyServiceImpl implements IMentorClassifyService {
    @Autowired
    private MentorClassifyMapper mentorClassifyMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询导师分类
     *
     * @param mentorClassifyId 导师分类主键
     * @return 导师分类
     */
    @Override
    public MentorClassify selectMentorClassifyByMentorClassifyId(Long mentorClassifyId) {
        return mentorClassifyMapper.selectMentorClassifyByMentorClassifyId(mentorClassifyId);
    }

    /**
     * 查询导师分类列表
     *
     * @param mentorClassify 导师分类
     * @return 导师分类
     */
    @Override
    public List<MentorClassify> selectMentorClassifyList(MentorClassify mentorClassify) {
        return mentorClassifyMapper.selectMentorClassifyList(mentorClassify);
    }

    /**
     * 新增导师分类
     *
     * @param mentorClassify 导师分类
     * @return 结果
     */
    @Override
    public int insertMentorClassify(MentorClassify mentorClassify) {
        mentorClassify.setCreateTime(DateUtils.getNowDate());
        return mentorClassifyMapper.insertMentorClassify(mentorClassify);
    }

    /**
     * 修改导师分类
     *
     * @param mentorClassify 导师分类
     * @return 结果
     */
    @Override
    public int updateMentorClassify(MentorClassify mentorClassify) {
        return mentorClassifyMapper.updateMentorClassify(mentorClassify);
    }

    /**
     * 批量删除导师分类
     *
     * @param mentorClassifyIds 需要删除的导师分类主键
     * @return 结果
     */
    @Override
    public int deleteMentorClassifyByMentorClassifyIds(Long[] mentorClassifyIds) {
        return mentorClassifyMapper.deleteMentorClassifyByMentorClassifyIds(mentorClassifyIds);
    }

    /**
     * 删除导师分类信息
     *
     * @param mentorClassifyId 导师分类主键
     * @return 结果
     */
    @Override
    public int deleteMentorClassifyByMentorClassifyId(Long mentorClassifyId) {
        return mentorClassifyMapper.deleteMentorClassifyByMentorClassifyId(mentorClassifyId);
    }

    /**
     * 实体数据补全
     *
     * @param mentorClassify 实体
     * @param userId         用户id
     * @param crateType      创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(MentorClassify mentorClassify, Long userId, Integer crateType) {
        //主键
        if (mentorClassify.getMentorClassifyId() == null || "".equals(mentorClassify.getMentorClassifyId())) {
            mentorClassify.setMentorClassifyId(ExtHelper.toString(idGeneratorSnowflake.nextId()));
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (mentorClassify.getCreateBy() == null) {
                mentorClassify.setCreateBy(userId.toString());
            }
            if (mentorClassify.getCreateTime() == null) {
                mentorClassify.setCreateTime(DateUtils.getNowDate());
            }
        }
        //修改人
        if (mentorClassify.getModifyBy() == null) {
            mentorClassify.setModifyBy(userId);
        }
        //修改时间
        if (mentorClassify.getModifyTime() == null) {
            mentorClassify.setModifyTime(DateUtils.getNowDate());
        }
    }

}
